#!/usr/bin/env python3

###
# Author: Samir Nasher Taher
# License: AGPLv3,  for the license text see LICENSE
# Description: This script measures latency via different ways and exports it into a csv.
###

from getTests import getTests

from modules import CONFIG
import argparse, csv, numpy as np

CSVFOLDER="csvs/"

"""
csvs are built like this:
<HOST>.csv
and each row is one test, according to getTests.py, so:
    [ 1, 2, 3] -> first test in getTests.getTests()
    [ 2, 3, 5] -> second
This obviously only works if after makecsvs, the file were not messed up.
"""

def genCsv(host):
    tests = getTests(host)
    with open(CSVFOLDER+host+".csv", 'w') as outfile:
        writer = csv.writer(outfile)
        for test in tests:
            name = test.getName()
            print(f"Starting test: {name} for {host}")
            y_vals = test.getResults()
            writer.writerow(y_vals)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Utility to test latency.')
    parser.add_argument('hosts', nargs='+', help='hosts to test')

    args = parser.parse_args()
    hosts = args.hosts

    for host in hosts:
        genCsv(host)

